package com.test.service.impl;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.test.dao.TopicDao;
import com.test.domain.Forum;
import com.test.domain.Topic;
import com.test.domain.User;
import com.test.service.TopicService;

public class TopicServiceImpl implements TopicService{
	private TopicDao topicDao;
	
	public TopicDao getTopicDao() {
		return topicDao;
	}

	public void setTopicDao(TopicDao topicDao) {
		this.topicDao = topicDao;
	}

	@Override
	public boolean addTopic(Topic topic) {
		// TODO Auto-generated method stub
		User user = (User)ActionContext.getContext().getSession().get("user");
		String reqIp = ServletActionContext.getRequest().getRemoteAddr();
		if(user!=null||reqIp!=null){
			System.out.println("=============在业务逻辑层能获得的登录用户名为："+user.getName()+",请求IP为："+reqIp+".===========");
		}else{
			System.out.println("在业务层（service）是拿不到表现层数据的！");
		}
		return topicDao.add(topic);
	}

	@Override
	public boolean deleteTopic(Integer id) {
		// TODO Auto-generated method stub
		return topicDao.delete(id);
	}

	@Override
	public boolean updateTopic(Topic topic) {
		// TODO Auto-generated method stub
		return topicDao.update(topic);
	}

	@Override
	public Topic findTopicById(Integer id) {
		// TODO Auto-generated method stub
		return topicDao.getById(id);
	}

	@Override
	public List<Topic> findAllTopic() {
		// TODO Auto-generated method stub
		return topicDao.findAll();
	}

	@Override
	public List<Topic> findTopicByForum(Forum forum) {
		// TODO Auto-generated method stub
		return topicDao.findByForum(forum);
	}

}
